package git.bds.nyc.applet.api.convert;

import git.bds.nyc.applet.api.model.vo.order.OrderDataVO;
import git.bds.nyc.applet.api.model.vo.order.OrderVO;
import git.bds.nyc.communal.model.domain.Address;
import git.bds.nyc.communal.model.domain.ContractOrder;
import git.bds.nyc.communal.model.dto.OrderDataDTO;
import git.bds.nyc.itext.PdfData;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author 成大事
 * @since 2023/2/3 16:31
 */
@Mapper
public interface OrderConvert {

    OrderConvert INSTANCE = Mappers.getMapper(OrderConvert.class);


    /**
     * 订单转VO
     *
     * @param list 列表
     * @return {@link List}<{@link OrderVO}>
     */
    List<OrderVO> toOrderVO(List<ContractOrder> list);


    /**
     * 订购数据vo
     *
     * @param orderDataDTO 订单数据dto
     * @return {@link OrderDataVO}
     */
    @Mapping(source = "unSigned",target = "unSigned",defaultValue = "0")
    @Mapping(source = "signed",target = "signed",defaultValue = "0")
    @Mapping(source = "refuseToSign",target = "refuseToSign",defaultValue = "0")
    @Mapping(source = "successfulTrade",target = "successfulTrade",defaultValue = "0")
    OrderDataVO toOrderDataVO(OrderDataDTO orderDataDTO);


    /**
     * 到pdf数据
     *
     * @param contractOrder     合同订单
     * @param sellerAddressInfo 卖家地址信息
     * @param buyAddressInfo    购买地址信息
     * @param totalPrice        总价
     * @param totalAmount       总额
     * @param year              年
     * @param month             月
     * @param day               白天
     * @return {@link PdfData}
     */
    @Mapping(source = "buyAddressInfo.consignee",target = "partyA")
    @Mapping(source = "sellerAddressInfo.consignee",target = "partyB")
    @Mapping(source = "contractOrder.productSpecies",target = "species")
    @Mapping(source = "contractOrder.productVariety",target = "varieties")
    @Mapping(source = "contractOrder.orderWeight",target = "quantity")
    @Mapping(source = "contractOrder.unitPrice",target = "unitPrice")
    @Mapping(source = "totalPrice",target = "totalPrice")
    @Mapping(source = "totalAmount",target = "totalAmount")
    @Mapping(expression = "java(buyAddressInfo.getLocation() + buyAddressInfo.getDetailedAddress())",target = "partyAContactAddress")
    @Mapping(expression = "java(sellerAddressInfo.getLocation() + sellerAddressInfo.getDetailedAddress())",target = "partyBContactAddress")
    @Mapping(source = "buyAddressInfo.phone",target = "partyAContactNumber")
    @Mapping(source = "sellerAddressInfo.phone",target = "partyBContactNumber")
    @Mapping(source = "year",target = "year")
    @Mapping(source = "month",target = "month")
    @Mapping(source = "day",target = "day")
    PdfData toPdfData(ContractOrder contractOrder, Address sellerAddressInfo, Address buyAddressInfo, BigDecimal totalPrice,String totalAmount,int year,int month,int day);

}
